package geppetto.phraseHMM.phraseExtraction.extractedphrase.writer;

import geppetto.cat.corpus.BilingualCorpus;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairWriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;


public class ExtractionTableWriter implements ExtractedPhrasePairWriter{
	PrintStream _out;
	PrintStream _headers;
	PrintStream _info;
	BilingualCorpus _corpus;
	
	public ExtractionTableWriter(BilingualCorpus corpus,String output, String encoding) throws FileNotFoundException, UnsupportedEncodingException {
		_out = new PrintStream(new File(output),encoding);
		_headers = new PrintStream(new File(output + ".headers"), encoding);
		_info = new PrintStream(new File(output + ".info"), encoding);
		_corpus = corpus;
	}

	public void initialize() {
	    
	}
	
	@Override
	public void write(ExtractedPhrasePair epp) {
		_out.println(epp.stringPhraseExtraction());	
	}

	@Override
	public void writeHeaders() {
		_headers.println(ExtractedPhrasePair.getHeaders());				
	}
	
	@Override
	public void writeInfo(String key, String value) {
		_info.println(key + "=" + value);
	}
	
	public void close() {
	    _out.close();
	    _headers.close();
	    _info.close();
	}
}
